<?php
class authActions extends myActions
{
  public function executeLogin(sfWebRequest $request)
  {
    $pathInfoArray = $request->getPathInfoArray();

    if ($request->isXmlHttpRequest())
    {
      // ......

      return sfView::NONE;
    }
    else
    {
      if ($this->getUser()->isAuthenticated())
      {
        $this->redirect('index/index');
      }

      // login request
      if ($request->hasParameter('password'))
      {
        $id       = $request->getParameter('id');
        $password = $request->getParameter('password');
        $this_url     = 'auth/login';

        if (UserPeer::login($id, $password))
        {
          $default_url  = 'index/index';
          $requested_uri = $this->getUser()->getAttribute('request_uri', $default_url);
          if ($requested_uri == $this_url)
          {
            $requested_uri = $default_url;
          }

          $this->getUser()->setAttribute('request_uri', null);
        }
        else
        {
          $requested_uri = $this_url;
        }

        $this->redirect($requested_uri);
      }
      else
      {
        $this->getUser()->setAttribute('request_uri', $pathInfoArray["REQUEST_URI"]);
        $this->setLayout('lander');
      }
    }

  }

  public function executeSignup(sfWebRequest $request)
  {

  }

  public function executeLogout(sfWebRequest $request)
  {
    $this->getUser()->setAuthenticated(false);

    if ($request->isXmlHttpRequest())
    {
      return $this->sendData(true);
    }
    else
    {
      $this->redirect('index/index');
    }
  }

}
